﻿
Imports System.Text

Public Class CError
Inherits Exception

Private Const __LENCODCLASE__ As Integer = 5

Private _ID_ERROR            As Integer
Private _CODCLASE            As String
Private _ENCABEZADO          As String 
Private _DESC_ERROR          As String 
Private _DESC_ERROR_MOSTRADO As String 
Private _LINEA_ERROR_INI     As Integer
Private _LINEA_ERROR_FIN     As Integer
Private _ATRAPADO            As Boolean



Public Sub new()
   _ATRAPADO = False
End Sub



Public Property ID_ERROR() As integer
    Get
        Return _ID_ERROR
    End Get
    Set(ByVal value As integer)
        _ID_ERROR = value
    End Set
End Property


Public Property CODCLASE() As String
    Get
        Return _CODCLASE
    End Get
    Set(ByVal value As String)
         If value.Length > __LENCODCLASE__ then 
            _CODCLASE = value.Substring(0,__LENCODCLASE__-1) 
         Else 
             _CODCLASE = value
         End If
        
    End Set
End Property


Public Property ENCABEZADO() As String
    Get
        Return _ENCABEZADO
    End Get
    Set(ByVal value As String)
        _ENCABEZADO = value
    End Set
End Property


Public Property DESC_ERROR() As String
    Get
        Return _DESC_ERROR 
    End Get
    Set(ByVal value As String)
        _DESC_ERROR = value
    End Set
End Property


Public Property DESC_ERROR_MOSTRADO() As String
    Get
        Return _DESC_ERROR_MOSTRADO 
    End Get
    Set(ByVal value As String)
        _DESC_ERROR_MOSTRADO = value
    End Set
End Property


Public Property LINEA_ERROR_INI() As integer
    Get
        Return _LINEA_ERROR_INI
    End Get
    Set(ByVal value As integer)
        _LINEA_ERROR_INI = value
    End Set
End Property


Public Property LINEA_ERROR_FIN() As integer
    Get
        Return _LINEA_ERROR_FIN
    End Get
    Set(ByVal value As integer)
        _LINEA_ERROR_FIN = value
    End Set
End Property

Public Property ATRAPADO() As Boolean
    Get
        Return _ATRAPADO
    End Get
    Set(ByVal value As Boolean)
        _ATRAPADO = value
    End Set
End Property



Public Shared Sub MostrarMensaje(ByRef clave as Integer, ByRef pLstError As Dictionary(Of integer, CError))
  Dim sMensage  = New StringBuilder("")
  Dim MiError as CError
  MiError = pLstError.Item(clave)


  sMensage.Append(MiError._CODCLASE)   '5 caracteres (__LENCODCLASE__)
  sMensage.Append(MiError.ID_ERROR )   'n Caracteres
  sMensage.Append("_")
  sMensage.Append(MiError.LINEA_ERROR_INI) 'n Caracteres
  sMensage.Append("-")   
  sMensage.Append(MiError.LINEA_ERROR_FIN) 'n Caracteres 
  sMensage.Append(": ")
  sMensage.Append(MiError.DESC_ERROR_MOSTRADO)

  
  MessageBox.Show(sMensage.ToString, MiError.ENCABEZADO,MessageBoxButton.OK,MessageBoxImage.Error)    

End Sub

Public Shared Sub MostrarMensaje(ByRef pError As CError)
  Dim sMensage  = New StringBuilder("")
  Dim MiError as CError = pError
  


  sMensage.Append(MiError._CODCLASE)   '5 caracteres (__LENCODCLASE__)
  sMensage.Append(MiError.ID_ERROR )   'n Caracteres
  sMensage.Append("_")
  sMensage.Append(MiError.LINEA_ERROR_INI) 'n Caracteres
  sMensage.Append("-")   
  sMensage.Append(MiError.LINEA_ERROR_FIN) 'n Caracteres 
  sMensage.Append(": ")
  sMensage.Append(MiError.DESC_ERROR_MOSTRADO)

  
  MessageBox.Show(sMensage.ToString, MiError.ENCABEZADO,MessageBoxButton.OK,MessageBoxImage.Error)    

End Sub


End Class
